package com.ruoyi.web.controller.dangerControl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.dangerControl.dto.HdTrainDto;
import com.ruoyi.dangerControl.vo.HdTrainVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dangerControl.domain.HdTrain;
import com.ruoyi.dangerControl.service.IHdTrainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隐患-培训管理Controller
 *
 * @author lth
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/dangerControl/train")
public class HdTrainController extends BaseController
{
    @Autowired
    private IHdTrainService hdTrainService;

    /**
     * 查询隐患-培训管理列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:train:list')")
    @GetMapping("/list")
    public TableDataInfo list(HdTrain hdTrain)
    {
        startPage();
        List<HdTrain> list = hdTrainService.selectHdTrainList(hdTrain);
        return getDataTable(list);
    }

    /**
     * 导出隐患-培训管理列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:train:export')")
    @Log(title = "隐患-培训管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HdTrain hdTrain)
    {
        List<HdTrain> list = hdTrainService.selectHdTrainList(hdTrain);
        ExcelUtil<HdTrain> util = new ExcelUtil<HdTrain>(HdTrain.class);
        util.exportExcel(response, list, "隐患-培训管理数据");
    }

    /**
     * 获取隐患-培训管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:train:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hdTrainService.selectHdTrainById(id));
    }

    /**
     * 新增隐患-培训管理
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:train:add')")
    @Log(title = "隐患-培训管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HdTrain hdTrain)
    {
        long id = new SnowflakeIdUtils(5, 8).nextId();
        hdTrain.setId(id);
        hdTrain.setCode("HDTR-"+(id+1));
        return toAjax(hdTrainService.insertHdTrain(hdTrain));
    }

    /**
     * 修改隐患-培训管理
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:train:edit')")
    @Log(title = "隐患-培训管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HdTrain hdTrain)
    {
        return toAjax(hdTrainService.updateHdTrain(hdTrain));
    }

    /**
     * 删除隐患-培训管理
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:train:remove')")
    @Log(title = "隐患-培训管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hdTrainService.deleteHdTrainByIds(ids));
    }


    /**
     *    培训管理-编辑
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:train:query')")
    @GetMapping("/getInfo")
    public HdTrainDto getInfo(@RequestBody HdTrainVo vo){
        return hdTrainService.getInfo(vo);
    }





}
